package com.aaa.service.impl;

import com.aaa.dao.Test_plan_sasDao;
import com.aaa.entity.Test_plan;
import com.aaa.service.Test_plan_sasService;
import com.aaa.util.Enum01;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Random;

@Service
public class Test_plan_sasServiceImpl implements Test_plan_sasService {

    @Autowired
    private Test_plan_sasDao plan_sasDao;

    /**
    * @Author: WTH
    * @Description: 查询，分页
    * @Date:2022-07-02 15:03
    * @Params:
    */
    @Override
    public Page<Test_plan> selectSasPlan(Test_plan plan_sas) {
        Page<Test_plan> plan_sas1 = PageHelper.startPage(plan_sas.getPage(), plan_sas.getLimit());
        List<Test_plan> test_plan_sas = plan_sasDao.selectSasPlan(plan_sas);
        Page sas= (Page) test_plan_sas;
        return sas;
    }

    /**
    * @Author: WTH
    * @Description: 新增,生成随机六位数
    * @Date:2022-07-02 16:33
    * @Params:
    */
    @Override
    public Enum01 addSasPlan(Test_plan plan_sas) {
        Random six=new Random();
        String results="";
        for(int a=0;a<6;a++){
            results=results+six.nextInt(10);
        }
        Integer result=Integer.parseInt(results);
        //赋值
        plan_sas.setTest_code(result);
        int i = plan_sasDao.addSasPlan(plan_sas);
        if(i>0){
            return Enum01.SUCCESS;
        }else{
            return Enum01.FAIL;
        }
    }

    /**
    * @Author: WTH
    * @Description: 删除
    * @Date:2022-07-02 16:41
    * @Params:
    */
    @Override
    public boolean deleteSasPlan(String id) {
        int i = plan_sasDao.deleteSasPlan(id);
        if(i>0){
            return true;
        }else{
            return false;
        }
    }

    /**
    * @Author: WTH
    * @Description: 修改
    * @Date:2022-07-02 16:47
    * @Params:
    */
    @Override
    public Enum01 updateSasPlan(Test_plan plan_sas) {
        int i = plan_sasDao.updateSasPlan(plan_sas);
        if(i>0){
            return Enum01.SUCCESS;
        }else{
            return Enum01.FAIL;
        }
    }

    /**
    * @Author: WTH
    * @Description: 根据邀请码查询
    * @Date:2022-07-07 15:49
    * @Params:
    */
    @Override
    public Test_plan selectByCode(Integer test_code) {
        Test_plan test_plan = plan_sasDao.selectByCode(test_code);
        return test_plan;
    }
}
